home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_359 / dice / dice.lzh / lib / amiga / chkabort.c < prev    next >
C/C++ Source or Header  |  1990-05-17  |  1KB  |  71 lines

  1.  
  2. /*
  3.  *  BREAK.C
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  *
  7.  *  Internal routine to check for ^C.    NOTE, ^C is cleared before we
  8.  *  write ^C\n because write itself calls chkabort().
  9.  */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/tasks.h>
  13. #include <exec/execbase.h>
  14. #include <libraries/dos.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <signal.h>
  18.  
  19. typedef int (*fptr)();
  20.  
  21. static int brk();
  22.  
  23. /*
  24.  *  _SigIntFunc() is set by signal() if SIGINT is something other than the
  25.  *  default.  The reason for this is so the signal code is not included in
  26.  *  the executable unless explicitly called.
  27.  */
  28.  
  29. extern struct ExecBase *SysBase;
  30. static int (*_BrkFunc)() = brk;
  31. void (*_SigIntFunc)(int);
  32.  
  33. void
  34. chkabort()
  35. {
  36.     struct Task *task = SysBase->ThisTask;
  37.  
  38.     if (task->tc_SigRecvd & SIGBREAKF_CTRL_C) {
  39.     SetSignal(0, SIGBREAKF_CTRL_C);
  40.     if ((*_BrkFunc)()) {
  41.         write(2, "^C\n", 3);
  42.         exit(EXIT_FAILURE);
  43.     }
  44.     }
  45. }
  46.  
  47. static int
  48. brk()
  49. {
  50.     if (_SigIntFunc) {
  51.     (*_SigIntFunc)(SIGINT);     /*  func might exit     */
  52.     return(0);                  /*  do not exit         */
  53.     }
  54.     return(1);
  55. }
  56.  
  57. fptr
  58. onbreak(func)
  59. fptr func;
  60. {
  61.     fptr old = _BrkFunc;
  62.  
  63.     if (func == NULL) {
  64.     _BrkFunc = brk;
  65.     } else {
  66.     _BrkFunc = func;
  67.     }
  68.     return(old);
  69. }
  70.  
  71.